package com.funong.matrix.biz.base.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.funong.matrix.biz.base.entity.SysTagEntity;
import com.funong.matrix.biz.base.mapper.SysTagMapper;
import com.funong.matrix.core.base.Dao;
import com.funong.matrix.core.base.FunongBaseDao;
import com.funong.matrix.core.dto.QueryDTO;
import org.aspectj.lang.annotation.Aspect;

/**
 * @author : NaNa
 * @since : 2023-05-19 16:40
 **/
@Aspect
@Dao
public class SysTagDao extends FunongBaseDao<SysTagMapper, SysTagEntity> {

    public IPage<SysTagEntity> queryTag(QueryDTO<SysTagEntity> queryDTO) {
        Page<SysTagEntity> page = new Page<>(queryDTO.getPageNo(), queryDTO.getPageSize());
        ObjectMapper mapper = new ObjectMapper();
        SysTagEntity sysTagEntity = mapper.convertValue(queryDTO.getCondition(),SysTagEntity.class);

        return this.getBaseMapper().selectPage(page, Wrappers.<SysTagEntity>lambdaQuery()
                .like(StringUtils.isNotEmpty(sysTagEntity.getName()), SysTagEntity::getName, sysTagEntity.getName())
        );
    }
}
